﻿@page "/CKNOUpdataPage"
@inject CKDServer cKDServer
@using System.ComponentModel
@using AntDesign.TableModels
@inject ModalService _modalService
@inject MessageService _message
<h3>销售出库单</h3>
<div>
    <Row>
        <Col Span="24">请选择客户代码</Col>
    </Row>
    <Row>
        <Col Span="24">
        <Select style="width:100%" DataSource="@F_YHKJ_ZJMList"
                AllowClear="true"
                ValueOnClear="@("")"
                TItem="XSCKDLIST"
                TItemValue="string"
                @bind-Value="@ZJMSelet"
                ValueName="@nameof(XSCKDLIST.F_YHKJ_ZJM)"
                LabelName="@nameof(XSCKDLIST.F_YHKJ_ZJM)"
                OnSelectedItemChanged="@ZJMSelectChange">
        </Select>
        </Col>
    </Row>
    <Row>
        <Col style="width:100%">客户名称</Col>
        <Col style="width:100%">
        <Input style="width:100%" @bind-Value="@FCustomerName" />
        </Col>
    </Row>
    <Row>
        <Col Span="24">请选择物流公司</Col>
    </Row>
    <Row>
        <Col Span="24">
        <Select style="width:100%" DataSource="@F_YHKJ_WLGSList"
                AllowClear="true"
                ValueOnClear="@("")"
                @bind-Value="@WLGSSelect"
                ValueName="@nameof(XSCKDLIST.F_YHKJ_WLGS)"
                LabelName="@nameof(XSCKDLIST.F_YHKJ_WLGS)"
                >
        </Select>
        </Col>
    </Row>
    <Row>
        <Col Span="24">
        <br>
        <Button style="width:100%" Type="@ButtonType.Primary" @onclick="@Creat">查询没有扫码验证的批号</Button>
       
        @*<Button style="width:100%" Type="@ButtonType.Primary" @onclick="@Creat2">提交审核</Button>*@
        <br>
        <br>
        </Col>
    </Row>
    @if (UnVerificationList != null)
    {
        <div class="order-contents">
            <h5>未扫码验证信息</h5>

            @foreach (var item in UnVerificationList)
            {
                <Row>

                    <GridCol Span="16">
                        <input Type="text" Value="@String.Format("批号:{0}",item.Flot)" style="border:none">
                    </GridCol>
                    <GridCol Span="4">
                        <input Type="text" Value="@item.F_YHKJ_MZ" style="border:none">
                    </GridCol>
                    <GridCol Span="4">
                        <input Type="text" Value="@item.Position" style="border:none">
                    </GridCol>
                </Row>
            }
        </div>
    }





    @* <Col Span="24">
    <label>@Result</label>
    </Col>*@



</div>


@code {
    string Result { get; set; }
    ObservableCollection<XSCKDLIST> DataList { get; set; } = new ObservableCollection<XSCKDLIST>();
    ObservableCollection<XSCKDLIST> F_YHKJ_ZJMList { get; set; } = new ObservableCollection<XSCKDLIST>();

    ObservableCollection<XSCKDLIST> F_YHKJ_WLGSList { get; set; } = new ObservableCollection<XSCKDLIST>();

    IEnumerable<XSCKD> UnVerificationList { get; set; }
    private string _ZJMSelect;

    public string ZJMSelet
    {
        get { return _ZJMSelect; }
        set
        {
            _ZJMSelect = value;

        }
    }
    private string WLGSSelect;


    string FCustomerName;

    protected override async Task OnInitializedAsync()
    {
        Result = "";
        var lists = await cKDServer.GetXSCKDLISTS();

        if (lists != null)
        {
            foreach (var item in lists)
            {
                DataList.Add(item);
            }
            var zjm = DataList.Where(e=>e.F_YHKJ_ZJM!=null).GroupBy(e => e.F_YHKJ_ZJM).Select(e => e.First());
            if(zjm!=null)
            {
                foreach (var item in zjm)
                {
                    F_YHKJ_ZJMList.Add(item);
                }
            }
           
        }

        base.OnInitialized();
    }
    private async Task init()
    {

        var lists = await cKDServer.GetXSCKDLISTS();
        DataList.Clear();
        foreach (var item in lists)
        {
            DataList.Add(item);
        }
        this.StateHasChanged();
    }
    private void ZJMSelectChange(XSCKDLIST xsckd)
    {
        FCustomerName = DataList.First(e => e.F_YHKJ_ZJM == ZJMSelet).FCustomerName;
        var wlgss = DataList.Where(e => e.F_YHKJ_ZJM == ZJMSelet).GroupBy(e => e.F_YHKJ_WLGS).Select(e => e.First());
        F_YHKJ_WLGSList.Clear();
        foreach (var item in wlgss)
        {
            F_YHKJ_WLGSList.Add(item);
        }
        WLGSSelect = F_YHKJ_WLGSList.FirstOrDefault(e => e.F_YHKJ_ZJM == ZJMSelet).F_YHKJ_WLGS;

        //this.StateHasChanged();
    }
   
    private async Task Creat()
    {
        _modalService.Confirm(new ConfirmOptions()
            {
                Title = $"提示",
                Icon =@<Icon Type="exclamation-circle" Theme="Outline"></Icon>,
            OkText = "确认",
            OnOk = async (e) =>
            {
                UnVerificationList = await cKDServer.GetXSCKDNOUPdata(ZJMSelet,WLGSSelect);
                if (UnVerificationList == null || UnVerificationList.Count() == 0)
                {
                    _message.Info("该销售出库单表没有扫码检验的的批号");
                }
                //Result = "";

                //foreach (var item in aa)
                //{
                //    Result += $"批号：{item.Flot}\r\n";

                //}
                this.StateHasChanged();
            },
            CancelText = "取消",
            Content = "是否提交？",
        });
    }

    //private async Task Creat2()
    //{
    //    _modalService.Confirm(new ConfirmOptions()
    //        {
    //            Title = $"提示",
    //            Icon =@<Icon Type="exclamation-circle" Theme="Outline"></Icon>,
    //        OkText = "确认",
    //        OnOk = async (e) =>
    //        {
    //            var aa = await cKDServer.submitXSCKD(selet);

    //            _message.Info("该盘点表没有待录入的批号");


    //        },
    //        CancelText = "取消",
    //        Content = "是否提交？",
    //    });

    //}


}
